<?php

namespace App\Models;

use Dcat\Admin\Traits\HasDateTimeFormatter;

use Illuminate\Database\Eloquent\Model;

/**
 * App\Models\UserBank
 *
 * @property int $id
 * @property int $user_id 用户ID
 * @property string $bank_name 开户行名称
 * @property string $bank_num 银行卡号
 * @property string $name 开户姓名
 * @property \Illuminate\Support\Carbon|null $created_at
 * @property \Illuminate\Support\Carbon|null $updated_at
 * @method static \Illuminate\Database\Eloquent\Builder|UserBank newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|UserBank newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|UserBank query()
 * @method static \Illuminate\Database\Eloquent\Builder|UserBank whereBankName($value)
 * @method static \Illuminate\Database\Eloquent\Builder|UserBank whereBankNum($value)
 * @method static \Illuminate\Database\Eloquent\Builder|UserBank whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|UserBank whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|UserBank whereName($value)
 * @method static \Illuminate\Database\Eloquent\Builder|UserBank whereUpdatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|UserBank whereUserId($value)
 * @mixin \Eloquent
 * @property-read \App\Models\User|null $user
 */
class UserBank extends Model
{
	use HasDateTimeFormatter;
    protected $table = 'user_banks';

    protected $fillable = ['user_id','bank_name','bank_num','name'];


    public static function getList($user_id): array
    {
        $pageSize = request()->input("pageSize",0);
        $list = self::query()->where("user_id",$user_id)->orderByDesc("id")->paginate($pageSize);
        return [
            'items'=> $list->items()
        ];
    }

    public function user(){
        return $this->hasOne(User::class,"id","user_id");
    }

}
